package cn.qyd.guava;

import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;

/**
 * @author 邱运铎
 * @date 2024-04-09 18:04
 */
public class CacheDemo {
    public static void main(String[] args) {
        LoadingCache<Integer, String> a = CacheBuilder.newBuilder().maximumSize(300).build(new CacheLoader<Integer, String>() {
            @Override
            public String load(Integer integer) throws Exception {
                System.out.println("current is cache");
                System.out.println(integer);
                return "hello";
            }
        });
        System.out.println(a.size());
        String v = a.getUnchecked(1);
        System.out.println(a.size());
        System.out.println(v);
    }
}
